package com.example.tianxi.yuexiuhhpatient;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.widget.Button;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TextView;

import java.util.Calendar;

public class PatientInfoActivity extends Activity {


    private TextView back;
    private TextView title;
    private  TextView action;


    //医生信息
    private TextView name;
    private TextView sex;
    private TextView tel;
    private TextView info;
    //预约的表格时间
//    private

    //预约表格
    private TableLayout tablelayout;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_patient_info);

        initView();
    }

    public void initView(){
        back = (TextView)findViewById(R.id.back);
        title = (TextView)findViewById(R.id.title);
        action = (TextView)findViewById(R.id.action);

        back.setText("返回");
        back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        title.setText("医生信息");
        action.setText("");

        name = (TextView)findViewById(R.id.name);
        sex = (TextView)findViewById(R.id.sex);
//        name = (TextView)findViewById(R.id.tel);
        info = (TextView)findViewById(R.id.info);

        tablelayout = (TableLayout)findViewById(R.id.tablelayout);

        initData();
    }

    public void initData(){

        Intent intent =getIntent();
        name.setText(intent.getStringExtra("name"));
        sex.setText(intent.getStringExtra("cate") + ", " + intent.getStringExtra("sex") + " 41岁 " + intent.getStringExtra("tel"));
        info.setText(intent.getStringExtra("info"));


//        TableRow tableRow = new TableRow(this);
//
//        TextView textView = new TextView(this);
//        Button button = new Button(this);
//        textView.setText("1");
//        button.setText("删除");
//        tableRow.addView(textView);
//        tableRow.addView(button);
//
//        tablelayout.addView(tableRow);


        //设置表格的四周，显示星期和上午下午晚上

        initDatetable();



    }

    public void initDatetable(){

        for(int i=0;i<4;i++) {
            TableRow tableRow = new TableRow(this);
            for (int j = 0; j < 8; j++) {
                TextView textView = new TextView(this);
//                textView.setId("");
                textView.setSingleLine(false);
                if (i == 0 && j!=0) {//表格上边框，显示星期和日期
                    textView.setText(getWeekString(j-1));
                }
                else if(i == 0 && j==0)
                    textView.setText("时间");
                else if(i==1 && j==0)
                    textView.setText("上午");
                else if(i==2 && j==0)
                    textView.setText("下午");
                else if(i==3 && j==0)
                    textView.setText("晚上");
                else{
                    textView.setText("预约");
//                    textView.setBackgroundColor(Color.GREEN);
                }

//                textView.setTextSize(15);

//                textView.isClickable();
                textView.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        new AlertDialog.Builder(PatientInfoActivity.this)
                                .setTitle("确认预约吗？")//应该还要显示选择的日期，
                                .setPositiveButton("确定", new DialogInterface.OnClickListener() {
                                    @Override
                                    public void onClick(DialogInterface dialog, int which) {

                                    }
                                })
                                .setNegativeButton("取消", new DialogInterface.OnClickListener() {
                                    @Override
                                    public void onClick(DialogInterface dialog, int which) {

                                    }
                                })
                                .create()
                                .show();
                    }
                });
                textView.setGravity(Gravity.CENTER);
                textView.setPadding(8, 8, 8, 8);
//                textView.setBackgroundColor(R.drawable.order_tablelayout_back_rowback);
                if (!(((i == 0) && (j == 0 || j == 7)) || (i == 3) && (j == 0 || j == 7)))//边角不设置
                    textView.setBackgroundResource(R.drawable.order_tablelayout_back_rowback);

                if(i==2 && j==4)
                    textView.setBackgroundColor(Color.GREEN);//设置颜色

                tableRow.addView(textView);
            }

            tablelayout.addView(tableRow);
        }

    }

    public String getWeekString(int index){

        Calendar cal=Calendar.getInstance();
        cal.add(Calendar.DATE,index);

        int y=cal.get(Calendar.YEAR);
        int m=cal.get(Calendar.MONTH)+1;
        int d=cal.get(Calendar.DATE);

        int which = cal.get(Calendar.DAY_OF_WEEK);

        String temp = "";
        if(which==1)
            temp = "日";
        else if(which==2)
            temp = "一";
        else if(which==3)
            temp = "二";
        else if(which==4)
            temp = "三";
        else if(which==5)
            temp = "四";
        else if(which==6)
            temp = "五";
        else if(which==7)
            temp = "六";
        else
            temp = "日";

        Log.v("日期",temp+"\n"+m+"."+d);

        return temp+"\n"+m+"."+d;
    }
    public void starttest(View source){
        Intent intent = new Intent(PatientInfoActivity.this,OnlineTestActivity.class);
        startActivity(intent);
    }

}
